﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chap10 {
    class Program {
        /* 
         *  This delegate can point to any method,
            taking two integers and returning an integer.
         */

        public delegate int BinaryOp(int x, int y);

        private static void Main(string[] args) {
            Console.WriteLine("chap 10");
            SimpleMath simpleMath = new SimpleMath();

            // Create a BinaryOp delegate object that
            // "points to" SimpleMath.Add().
            BinaryOp b = simpleMath.Add;
            b += simpleMath.Subtract;
            b += simpleMath.Add;
            DisplayDelegateInfo(b);

            // Invoke Add() method indirectly using delegate object.
            Console.WriteLine("10 + 10 is {0}", b(10, 10));

            Console.ReadLine();
        }

        private static void DisplayDelegateInfo(Delegate delObj) {
            // Print the names of each member in the
            // delegate's invocation list.
            foreach (Delegate d in delObj.GetInvocationList()) {
                Console.WriteLine("Method Name: {0}", d.Method);
                Console.WriteLine("Type Name: {0}", d.Target);
            }
        }
    }
}